//网络请求
import axios from 'axios';
import AppConfig from '@/constants/AppConfig.js';

const $axios = axios;

export default function() {
	var $app_config = AppConfig();
	var $base_url = $app_config.Base_Url;
	var $post_config = $app_config.POST_Cfg;
	
	
	var $url_get_Tags2Works = $base_url + "/admin/etag/v1/getTags2Works";
	
	var $url_add_entityTag = $base_url + "/admin/etag/v1/addEntityTag";
	var $url_edit_entityTag = $base_url + "/admin/etag/v1/edit2EntityTag";
	var $url_edit_sort2EntityTag = $base_url + "/admin/etag/v1/editSort2EntityTag";
	var $url_edit_uentityTag = $base_url + "/admin/etag/v1/edit2UEntityTag";
	var $url_edit_sort2UEntityTag = $base_url + "/admin/etag/v1/editSort2UEntityTag";
	//编辑实体标签隐藏排序
	var $url_hideIndex = $base_url + "/admin/etag/v1/hideIndex";
	var $url_del_uentityTag = $base_url + "/admin/etag/v1/delUEntityTag";
	
	return {
		getTags2Works: function(wid) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_get_Tags2Works, {
					wid: wid
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		hideIndex: function(etId, index) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_hideIndex, {
					etId: etId,
					index: index
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		//删除用户实体标签
		delUEntityTag: function(uetId) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_del_uentityTag, {
					uetId: uetId
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		addEntityTag: function(params) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_add_entityTag, {
					worksId: params.worksId,
					groupName: params.groupName, 
					etNames	: params.etNames, 
					fname	: params.fname, 
					etType: params.etType, 
					type: params.type,
					name: params.name,
					roleName: params.roleName,
					isSensitive: params.isSensitive,
					sort: params.sort
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		editEntityTag: function(params) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_edit_entityTag, {
					etId: params.etId,
					groupName: params.groupName, 
					etNames	: params.etNames, 
					fname	: params.fname, 
					etType: params.etType
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		editSort2EntityTag: function(sorts) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_edit_sort2EntityTag, {
					sorts: sorts
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		editSort2UEntityTag: function(sorts) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_edit_sort2UEntityTag, {
					sorts: sorts
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		editUserEntityTag: function(params) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_edit_uentityTag, {
					etId: params.etId,
					uetId: params.uetId,
					name: params.name, 
					roleName	: params.roleName, 
					isSensitive: params.isSensitive,
					sort: params.sort
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		}
	}
}